package com.ambow.core.controller;


import com.ambow.core.po.DqGame;
import com.ambow.core.po.DqWarehouse;
import com.ambow.core.service.DqGameService;
import com.ambow.core.service.DqWarehouseService;
import com.dq.gamepropaganda.common.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLWarning;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * warehouse库表 前端控制器
 * </p>
 *
 * @author dq
 * @since 2022-09-05
 */
//跨域
@CrossOrigin
@Api(tags="库")
@RestController
@RequestMapping("/admin/dqWarehouse")
public class DqWarehouseController {

    @Autowired
    private DqWarehouseService dqWarehouseService;
    @Autowired
    private DqGameService dqGameService;

    //查看自己有的游戏
    @PostMapping("/findGameListByRoleId")
    public R findGameListByRoleId(Integer roleId){
        //拿到有对应游戏id的集合
        List<DqWarehouse> gameList = dqWarehouseService.findGameListByRoleId(roleId);
        //创建空游戏list
        List<DqGame> games = new  ArrayList<DqGame>();
        for (DqWarehouse d : gameList) {
            games.add(dqGameService.getById(d.getGameId()));
        }
        if (games == null || games.size()<1){
            return R.error().message("仓库没有游戏");
        }else {
            return R.ok().data("gameList",games);
        }

    }









}

